capture log close
capture noisily log using "R:\Zentrale\ZB-S\Daten_FDSZ_Gastforscher\1_gafo\2016_0133\Figure 1.log", replace
capture noisily log using "Figure 1.log", replace

**** Load data in Stata
clear all
set more off
set maxvar 5000
capture noisily use "final_sample_03032023_pseudo.dta", clear
capture noisily use "R:\Zentrale\ZB-S\Daten_FDSZ_Gastforscher\1_gafo\2016_0133\data\Bundesbank Discussion Paper\final_sample_03032023.dta", clear



********************************************************************************
*  Aggregate external assets 
********************************************************************************


* positions of banks in DEU with never-sanctioned countries (smallsample == 0):
preserve 
qui keep if smallsample == 0 & abroad_CTRY == 0 // 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_nsan_DEU
}		
save temp_nsan_DEU.dta, replace
restore

* positions of banks abroad with never-sanctioned countries:
preserve 
qui keep if smallsample == 0 & abroad_CTRY == 1 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_nsan_abr
}		
save temp_nsan_abr.dta, replace
restore

* positions of banks outside EU with never-sanctioned countries:
preserve 
qui keep if smallsample == 0 & notEU_CTRY == 1 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_nsan_outEU
}		
save temp_nsan_outEU.dta, replace
restore

* positions of banks outside FATF with never-sanctioned countries:
preserve 
qui keep if smallsample == 0 & notFATF_CTRY == 1 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_nsan_outFATF
}		
save temp_nsan_outFATF.dta, replace
restore
	
* positions of banks in DEU with at least once sanctioned countries (smallsample == 1):
preserve 
qui keep if smallsample == 1 & abroad_CTRY == 0 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_san_DEU
}		
save temp_san_DEU.dta, replace
restore

* positions of banks abroad with at least once sanctioned countries:
preserve 
qui keep if smallsample == 1 & abroad_CTRY == 1 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_san_abr
}		
save temp_san_abr.dta, replace
restore

* positions of banks outside EU with at least once sanctioned countries:
preserve 
qui keep if smallsample == 1 & notEU_CTRY == 1 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_san_outEU
}		
save temp_san_outEU.dta, replace
restore

* positions of banks outside FATF with at least once sanctioned countries:
preserve 
keep if smallsample == 1 & notFATF_CTRY == 1 
collapse (sum) am100, by(datum)
foreach var of varlist am100  {
display "`var'"
rename `var' `var'_san_outFATF
}		
save temp_san_outFATF.dta, replace
restore	

* make graphs

preserve
use temp_nsan_DEU.dta, clear
qui merge 1:1 datum using temp_nsan_abr.dta, nogenerate
qui merge 1:1 datum using temp_nsan_outEU.dta, nogenerate
qui merge 1:1 datum using temp_nsan_outFATF.dta, nogenerate
qui merge 1:1 datum using temp_san_DEU.dta, nogenerate
qui merge 1:1 datum using temp_san_abr.dta, nogenerate
qui merge 1:1 datum using temp_san_outEU.dta, nogenerate
qui merge 1:1 datum using temp_san_outFATF.dta, nogenerate

twoway (line am100_nsan_DEU datum, lpattern(solid)) ///
       (line am100_nsan_abr datum, lpatter(longdash)) ///
	   (line am100_nsan_outEU datum, lpatter(shortdash_dot)) ///
	   (line am100_nsan_outFATF datum, lpatter(longdash_dot) ///
	   legend(on col(2) lab(1 "banks inside DEU") lab(2 "banks abroad") lab(3 "banks outside EU") lab(4 "banks outside FATF")) ///
	   xtitle(" ") ytitle("Euro (1,000)" " ") ///
	   title("Never Sanctioned Countries") subtitle(" ") ///
	   name(g1, replace) ) 
	   
graph save Figure1a.gph, replace	   

twoway (line am100_san_DEU datum, lpattern(solid)) ///
       (line am100_san_abr datum, lpatter(longdash)) ///
	   (line am100_san_outEU datum, lpatter(shortdash_dot)) ///
	   (line am100_san_outFATF datum, lpatter(longdash_dot) ///
	   legend(on col(2) lab(1 "banks inside DEU") lab(2 "banks abroad") lab(3 "banks outside EU") lab(4 "banks outside FATF")) ///
	   xtitle(" ") ytitle("Euro (1,000)" " ") ///
	   title("Sanctioned Countries") subtitle(" ") ///
	   name(g2, replace) ) 
	   
graph save Figure1b.gph, replace	   
	   
erase temp_nsan_DEU.dta
erase temp_nsan_abr.dta
erase temp_nsan_outEU.dta
erase temp_nsan_outFATF.dta
erase temp_san_DEU.dta
erase temp_san_abr.dta
erase temp_san_outEU.dta
erase temp_san_outFATF.dta

log close	
